#coding=utf8

from distutils.core import setup
from Cython.Build import cythonize
import os
import sys

def main():
    pyd_paths = []
    for _path, _folders, _files in os.walk(root):
        if _files and (len(_files)>=2) and ('__init__.py' in _files):
            for _f in _files:
                if (_f not in ['__init__.py', 'resources_rc.py', 'resources.py']) and _f.endswith('.py'):
                    pyd_paths.append(os.path.join(_path, _f).replace('\\', '/'))
    os.chdir(pyd_root)
    if pyd_paths:
        for _p in pyd_paths:
            print _p
            setup(ext_modules = cythonize(_p))
#main()

if __name__ == "__main__":
    arg = os.getenv('INPUT_VALUE')
    if arg:
        arg_list = [i for i in arg.split(' ') if i]
        if len(arg_list) != 2:
            raise ValueError('the args error!: %s' % str(arg_list))

        if not os.path.isdir(arg_list[-2]):
            raise ValueError('the args error!: %s' % str(arg_list))
        root= arg_list[-2]
        pyd_root= arg_list[-1]
        
    else:
        _root= os.getenv('INIT_PATH').replace('\\', '/')
        root = os.path.join(_root, 'src')
        if not os.path.isdir(root):
            raise ValueError('folder error!: %s' % str(root))
        pyd_root = os.path.join(_root, 'pyd')
    if not os.path.isdir(pyd_root):
        os.makedirs(pyd_root)
    main()


